<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<jsp:useBean id="user" class="entity.User" scope="session"/>
<jsp:useBean id="appointment" class="entity.Appointment" scope="request"/>
<jsp:useBean id="comments" class="java.util.ArrayList" scope="request"/>

<html>
	<head>
		<title>Recreation Manager - Detalji o terminu</title>
		<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
		<link rel="stylesheet" type="text/css" href="theme.css">
		<script type="text/javascript" src="scripts/linkfader.js"></script>
	</head>
	<c:if test="${user.userId==null}">
		<c:redirect url="./main.jsp" />
	</c:if>
	<body>
	<center>
	<c:import url="./header.jsp"></c:import>
	<table class="mainTable">
		<tr>
			<td width="200px" valign="top">
				<c:import url="./menu.jsp"></c:import>
			</td>			
			<td valign="top">
			<!-- itt kezdodik -->
			<table class="list">
			<thead>
				<tr>
					<th colspan="3"><h2>Detalji o utakmicu</h2></th>
				</tr>
				<tr>
					<th colspan="3">${appointment.location}</th>
				</tr>
			</thead>
			<tbody>
			<tr>
				<td>Datum: <fmt:formatDate value="${appointment.date}" pattern="dd.MM.yyyy" /> </td>
				<td>Od: <fmt:formatDate value="${appointment.from}" pattern="hh:mm"/></td>
				<td>Do: <fmt:formatDate value="${appointment.to}" pattern="hh:mm"/></td>
			</tr>
			<tr>
				<td>Naziv: ${appointment.footballMatch.name}</td>
				<td>Rezultat: ${appointment.footballMatch.goalHome} : ${appointment.footballMatch.goalGuest}</td>
				<td>MVP: ${appointment.footballMatch.mvp.firstName} ${appointment.footballMatch.mvp.lastName}</td>
			</tr>
			</tbody>
		</table>
		<table class="list">
			<thead>
				<tr>
					<th colspan = "3"><h3>Komentari</h3></th>	
				</tr>
			</thead>
			<tbody>
				<c:forEach items="${comments}" var="comment">
					<tr>
						<td>${comment.user.firstName} ${comment.user.lastName}</td>
						<td align="left"><fmt:formatDate value="${comment.date}" pattern="dd.MM.yyyy, hh:mm" /></td>
						<td align="right">
						&nbsp;
						<c:choose>
						  <c:when test="${user.type=='A'}"> 
						    <a href="./PrepareChangeComment?commentId=${comment.commentId}">Izmena</a>&nbsp;
							<a href="./DeleteComment?commentId=${comment.commentId}">Brisanje</a> 
						  </c:when>  
						  <c:otherwise> 
						    <c:if test="${user.userId==comment.user.userId}">
								<a href="./PrepareChangeComment?commentId=${comment.commentId}">Izmena</a>&nbsp;
								<a href="./DeleteComment?commentId=${comment.commentId}">Brisanje</a> 
							</c:if>
						  </c:otherwise> 
						</c:choose> 
						
						</td>
					</tr>
					<tr>
						<td><img src="./avatar/${comment.user.avatar}"/></td>
						<td colspan="2" valign="top" align="left">
							<table border="0" width="100%">
							<tr background="images/75pgreen.png">
								<td colspan="3"><font style="size: 12px;">${comment.text}</font></td>
							</tr>
							<tr>
								<td colspan="3">&nbsp;</td>
							</tr>
							<c:if test="${comment.userChanged!=null}">
								<tr background="images/75pwhite.png" >
									<td align="left" background="images/75pwhite.png">Ovaj post je izmenio</td>
									<td align="right" background="images/75pwhite.png">${comment.userChanged.firstName} ${comment.userChanged.lastName}:</td>
									<td align="left" background="images/75pwhite.png"><fmt:formatDate value="${comment.dateChanged}" pattern="dd.MM.yyyy, hh:mm" /></td>
								</tr>
							</c:if>
							</table>
						</td>
					</tr>
					<tr>
						<td colspan="3">&nbsp;</td>
					</tr>
				</c:forEach>
			</tbody>		
		</table>
		<form name="addCommentForm" action="./AddComment" method="post">
			<table background="images/75pgreen.png" width="100%">
				<tr>
					<td>Pošalji komentar:</td>
				</tr>
				<tr>
					<td><textarea name="comment" cols="50" rows="5"></textarea></td>
				</tr>
				<tr>
					<td>
					<input type="hidden" name="appId" value="${appointment.appointmentId}">
					<input type="submit" name="submit" value="Pošalji">
					</td>
				</tr>
			</table>
		</form>
			<!-- itt vegzodik -->
			</td>
		</tr>
	</table>
	
	
	

		
		
		
	</center>	
	</body>	
</html>